import {
    queryIndicators,
    queryAnalysis,
    queryStatistics,
    queryGetStatistics,
  } from '../services/index';
  
  export default {
      namespace: 'hotline',
    
      state: {
        IndicatorsResource: {},
        StatisticsResource: {},
        StatisticsResource1: [
          { time: '2019-01', total: 100, radio1: 28, radio2: 12 },
          { time: '2019-02', total: 80, radio1: 48, radio2: 10 },
          { time: '2019-03', total: 110, radio1: 18, radio2: 22 },
          { time: '2019-05', total: 130, radio1: 68, radio2: 32 },
          { time: '2019-06', total: 586, radio1: 14, radio2: 18 },
          { time: '2019-07', total: 320, radio1: 18, radio2: 72 },
          { time: '2019-08', total: 200, radio1: 38, radio2: 62 },
        ]
      },
    
      effects: {
        *queryIndicators({ payload }, { call, put }) {
          const data = yield call(queryIndicators, payload)
          const { success, message, status, ...other } = data
          if (success) {
            yield put({
              type: 'setState',
              payload: {
                IndicatorsResource: other.data,
              },
            })
          } else {
            throw data
          }
        },
        *queryAnalysis({ payload }, { call, put }) {
          // 解构 type，返回结果拼接
          const { type } = payload;
          const data = yield call(queryAnalysis, payload)
          const { success, message, status, ...other } = data
          if (success) {
            yield put({
              type: 'setState',
              payload: {
                [`AnalysisResource${type}`]: other.data,
              },
            })
          } else {
            throw data
          }
        },
        *queryStatistics({ payload }, { call, put }) {
          const { type } = payload;
          const data = yield call(queryStatistics, payload)
          const { success, message, status, ...other } = data
          if (success) {
            yield put({
              type: 'setState',
              payload: {
                [`StatisticsResource${type}`]: other.data,
              },
            })
          } else {
            throw data
          }
        },
        *queryGetStatistics({ payload }, { call, put }) {
          const { type } = payload;
          const data = yield call(queryGetStatistics, payload)
          const { success, message, status, ...other } = data
          if (success) {
            yield put({
              type: 'setState',
              payload: {
                [`GetStatisticsResource${type}`]: other.data,
              },
            })
          } else {
            throw data
          }
        },
      },
    
      reducers: {
        setState(state, action) {
          return {
              ...state,
              ...action.payload
          };
        }
      },
    }
    